<include file="Public/mobile_head"/>
<link href="{:ADDON_PUBLIC_PATH}/css.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
<body>
<div id="container" class="container">
	<form id="form" action="{:U('doAsk?ask_id='.$_GET['ask_id'].'&question_id='.$question['id'])}" method="POST"
	      onSubmit="return checkForm();">
		<div class="question_content qhead mt0">
			<notempty name="question.answer_time">
				<div class="leftTime">{$question.answer_time}</div>
			</notempty>
			<h4 class="title font16">{$question.title}</h4>

			<p class="q_tips">{$question.intro}</p>
		</div>
		<div class="quesiton_content">
			<input name="times" value="{$times}" type="hidden">
			<input name="question_id" value="{$question.id}" type="hidden">
			<input name="other_answer" id="other_answer" value="" type="hidden">
			<switch name="question.type">
				<case value="textarea">
					<!-- 文本框 -->
					<div class="form-item cf">
						<label class="item-label"><span class="check-tips"></span></label>

						<div class="controls">
							<textarea type="text" placeholder="请输入" class="text input-medium"
							          name="answer">{$data}</textarea>
						</div>
					</div>
				</case>
				<case value="checkbox">
					<volist name="extra" id="vo">
						<div class="voteItem" type="type_checkbox">
							<em class="check">&nbsp;</em>
							<input type="checkbox" value="{$key}" class="checkbox" name="answer[]">
							{$vo}
						</div>
					</volist>
				</case>
				<default/>
				<volist name="extra" id="vo">
					<div class="voteItem" type="type_radio">
						<em class="check">&nbsp;</em>
						<input type="radio" value="{$key}" class="radio" name="answer[]">
						{$vo}
					</div>
				</volist>
			</switch>
		</div>
		<div class="btnWrap" style="margin:0 60px">
			<a class="start_btn" href="javascript:;" onClick="$('#form').submit();">确认提交</a>
		</div>
	</form>

	<p class="copyright">{$system_copy_right}{$tongji_code}</p>
</div>
<script type="text/javascript">
	$(function () {
		var leftTime = parseInt($('.leftTime').text());
		setInterval(function () {
			leftTime--;
			$('.leftTime').text(leftTime);
			if (leftTime == 0) {
				window.location.href = $('#form').attr('action');
			}
		}, 1000);
	})
	var is_require = "{$question.is_must}";
	var widget = "{$question.type}";
	function checkForm() {
		if (is_require == '0') return true;

		var content = '';
		var msg = '请选择你的答案';
		if (widget == 'textarea') {
			content = $('textarea').val();
			msg = '请填写你的答案.';
		} else if (widget == 'checkbox') {
			content = $("input[type='checkbox']:checked").val();
		} else {
			$('.voteItem').each(function () {
				console.log($(this).hasClass('selected'));
				if ($(this).hasClass('selected')) {
					content = $(this).find('input').val();
				}
			});
			//content = $("input[type='radio']").prop("checked",true).val();
		}
		//console.log(content);
		//return false;
		if (content == '' || content == "undefined") {
			$.Dialog.fail(msg);
			return false;
		}

		return true;
	}
	$('.voteItem').click(function () {
		var type = $(this).attr("type");

		if ($(this).hasClass('selected')) {
			$(this).removeClass('selected');
			$(this).find('input').prop('checked', false);
		} else {
			if (type == "type_checkbox") {
				$(this).addClass('selected');
				$(this).find('input').prop('checked', true);
			} else if (type == "type_radio") {
				var obj = $(this);
				$('#other_answer').val(obj.find('input').val());
				obj.siblings().removeClass('selected');
				$('.voteItem').each(function () {
					$(this).find('input').prop("checked", false);
				});

				obj.addClass('selected');
				obj.find('input').prop("checked", true);
			}
		}
	})
	document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
		// 分享到朋友圈
		WeixinJSBridge.on('menu:share:timeline', function (argv) {
			WeixinJSBridge.invoke('shareTimeline', {
						"img_url": "{$ask.cover|get_cover_url}",
						"img_width": "640",
						"img_height": "640",
						"link": "{:addons_url('Ask://Ask/ask', $get_param)}",
						"desc": "{$ask.intro}",
						"title": "{$ask.title}"
					},
					function (res) {
						//分享到朋友圈成功
						if (res.err_msg == "share_timeline:ok") {
							//$.post("{:U('share','id='.I('id').'&fromuid='.$fromuid)}",function(e){alert(e);window.location.reload();});
						}
					});
		});
		WeixinJSBridge.on('menu:share:appmessage', function (argv) {
			WeixinJSBridge.invoke('sendAppMessage', {
						"img_url": "{$ask.cover|get_cover_url}",
						"img_width": "640",
						"img_height": "640",
						"link": "{:addons_url('Ask://Ask/ask', $get_param)}",
						"desc": "{$ask.intro}",
						"title": "{$ask.title}"
					},
					function (res) {
						//分享给好友成功
						if (res.err_msg == "send_app_msg:ok") {
							//$.post("{:U('share','id='.I('id').'&fromuid='.$fromuid)}",function(e){alert(e);window.location.reload();});
						}
					})
		});
	}, false);
</script>
<include file="Public/mobile_foot"/>
</body>
</html>